using System;
using System.Collections.Generic;
using Randomize.Core.Generators;

namespace Randomize.Core.Descriptors
{
    public class CollectionDescriptor<TCollectionItem> : GenerationDescriptor<IEnumerable<TCollectionItem>,
                                                             ICollectionDescriptor<TCollectionItem>>,
                                                         ICollectionDescriptor<TCollectionItem>
    {
        private int? _maxCount;

        private int? _minCount;

        private int? _count;

        private readonly IGenerationDescriptor<TCollectionItem> _itemDescriptor;

        public CollectionDescriptor(IGenerationDescriptor<TCollectionItem> itemDescriptor)
        {
            _itemDescriptor = itemDescriptor;
        }

        public override IGenerator<IEnumerable<TCollectionItem>> CreateGenerator(Random random)
        {
            return new CollectionGenerator<TCollectionItem>(random, _itemDescriptor.CreateGenerator(random));
        }

        public ICollectionDescriptor<TCollectionItem> WithMaxCount(int maxCount)
        {
            _maxCount = maxCount;
            return this;
        }

        public ICollectionDescriptor<TCollectionItem> WithMinCount(int minCount)
        {
            _minCount = minCount;
            return this;
        }

        public ICollectionDescriptor<TCollectionItem> WithCount(int count)
        {
            _count = count;
            return this;
        }
    }
}